import {ref} from 'vue'
import { defineStore } from 'pinia'

export interface IUserInfo{
    avatar:string
    nickname:string
    organizationId:number
    type:number
    userId:string
    username:string
}
export const useUserinfo = defineStore('userInfo', () => {
    const cacheLoginInfo=localStorage.getItem('login')
    let userInfo
    let userScope
    if(cacheLoginInfo){
       const {info,scopes}=JSON.parse(cacheLoginInfo).info
       userInfo=info
       userScope=scopes
    }
    const user = ref(userInfo)
    const scope = ref<string[]>(userScope)
    const setUser=({info,scopes}:{info:IUserInfo,scopes:string[]})=>{
        user.value=info
      scope.value=scopes
    }
    return { 
        user,
        setUser,
        userScope
    }
})